package com.xlx.openLink.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xlx.openLink.base.BasePage;
import com.xlx.openLink.base.BaseUtils;
import com.xlx.openLink.base.ThreadRunTimeExcption;
import com.xlx.openLink.dao.InformMapper;
import com.xlx.openLink.entity.pojo.Device;
import com.xlx.openLink.entity.pojo.Inform;
import com.xlx.openLink.enums.DevStatusEnum;
import com.xlx.openLink.enums.DevTypeEnum;
import com.xlx.openLink.enums.ResultCodeEnum;
import com.xlx.openLink.uitls.AssertUtils;
import com.xlx.openLink.uitls.Commuitls;
import com.xlx.openLink.vo.RequestDevtLst;
import com.xlx.openLink.vo.RequestInformtLst;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author seven
 * @create 2019-10-28 4:24
 **/
@Service
@Slf4j
public class InformService {
    @Autowired
    private InformMapper informMapper;


    /**
     * 分页查询
     *
     * @param request
     * @return
     */
    public BasePage<Inform> listByPage(RequestInformtLst request) {
        AssertUtils.isNotNull(new ThreadRunTimeExcption(ResultCodeEnum.ILLEGAL_PARAM_BLANK), request);
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<Inform> list = informMapper.listByPage(request);
        PageInfo pageInfo = new PageInfo(list);
        return new BasePage<Inform>(pageInfo.getList(), pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getTotal());
    }

    @Transactional
    public int add(Inform inform) {
        //参数校验
        AssertUtils.isNotNull(new ThreadRunTimeExcption(ResultCodeEnum.ILLEGAL_PARAM_BLANK), inform);
        AssertUtils.isNotNull(new ThreadRunTimeExcption(ResultCodeEnum.ILLEGAL_PARAM_BLANK), inform.getiAccount());
        AssertUtils.isNotNull(new ThreadRunTimeExcption(ResultCodeEnum.ILLEGAL_PARAM_BLANK), inform.getiType());
        //产看设备
        inform.setiUpdateDate(new Date());
        inform.setiCreateDate(new Date());
        inform.setiStatus("T");
        inform.setPkGuid(BaseUtils.createGUID());
        return informMapper.insertSelective(inform);
    }

    @Transactional
    public int option(Inform inform) {
        //参数校验
        AssertUtils.isNotNull(new ThreadRunTimeExcption(ResultCodeEnum.ILLEGAL_PARAM_BLANK), inform);
        //产看设备
        inform.setiUpdateDate(new Date());
        return informMapper.updateByPrimaryKeySelective(inform);
    }


    public Inform selectById(String pkGuid) {
        return informMapper.selectByPrimaryKey(pkGuid);
    }

    public List<Inform> selectValid() {
        return informMapper.selectValid();
    }


}


